package com.ibiaoke.system.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.system.entity.FloorItem;
import com.ibiaoke.system.entity.FloorItemExample;
import com.ibiaoke.system.mapper.FloorItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Created by Administrator on 2017/6/16.
 */
@Repository
public class FloorItemDao extends BaseDao<FloorItem,FloorItemExample,Integer,FloorItemMapper>{
    @Autowired
    private FloorItemMapper floorItemMapper;

    @Override
    public FloorItemMapper getMapper() {
        return floorItemMapper;
    }

    public int updateById(FloorItem floorItem) {
        FloorItemExample example = new FloorItemExample();
        example.createCriteria().andFloorItemIdEqualTo(floorItem.getFloorItemId());
        return updateByExampleSelective(floorItem,example);
    }

    public List<FloorItem> listFloorItems(List<Integer> floorIds) {
        FloorItemExample example = new FloorItemExample();
        example.createCriteria().andFloorIdIn(floorIds).andDelStatusEqualTo(CommonConsts.NO);
        example.setOrderByClause("sort");

        return selectByExample(example);
    }

    public List<FloorItem> listFloorItems(Integer floorId,Integer shopId) {
        FloorItemExample example = new FloorItemExample();
        FloorItemExample.Criteria criteria = example.createCriteria();
        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }
        criteria.andFloorIdEqualTo(floorId).andDelStatusEqualTo(CommonConsts.NO);
        List<FloorItem> listFloorItems = floorItemMapper.selectByExample(example);
        return listFloorItems;
    }
}
